<?php
require_once '../inc/configuration.php';
require_once '../inc/connexion_db.php';
require_once '../inc/fonctions_sql.php';

$message_action = "";

$action = isset($_POST["action"]) ? $action = $_POST["action"] : "";

if($action==1) {
    
    $tab_name_form = array(
        "id_contact",
        "rdv_date",
        "heure",
        "type_rdv",
        "objet",
        "observations",
    );
    
    $message_action = ajouter_donnees("rendez_vous", $tab_name_form);
}
?>

<!DOCTYPE html>

<html>
    <head>
        <meta charset="ISO-8859-1">
        <title></title>
         
        <?php require_once "../inc/css_js_bootstrap/css_js_bootstrap.php"; ?>
        
        <style>
            .table {
                width: 500px;
            }
            
            th {
                width: 35%;
                text-align: right;
            }
            textarea.form-control {
                /*background-color: #ccc;*/
                height: 150px;
            }
            
        </style>
    </head>
    <body>
        
        <?php require_once '../inc/menus/menu_principal.php'; ?>
        
        <h1>AJOUTER UN RENDEZ VOUS</h1>
        <?php if(!empty($message_action)) { ?>
            <div id="message_action" class="alert <?php echo $message_action["css_class"]; ?>"><?php echo $message_action["texte"]; ?></div>
        <?php } ?>
        <form name="form_ajouter" id="form_ajouter" method="post">
        <div>
            <table class="table table-bordered">
                <tr>
                    <th>Contact</th>
                    <td> <select name="id_contact" id="id_contact">
              <?php
        $sql = "SELECT id, raison_sociale FROM entreprises ";
        $req = mysqli_query($connexion_bd, $sql);
        
         ?>               
            <?php
            while($data_rdv = mysqli_fetch_assoc($req)) {
                $sql_rdv = "SELECT id, nom, prenom FROM contacts WHERE id_entreprise = ".$data_rdv["id"];
                echo "<br>".$sql_rdv."<br>";
                $req_rdv = mysqli_query($connexion_bd, $sql_rdv);
                while($data_ent = mysqli_fetch_assoc($req_rdv)) {
            ?>
                    <option value="<?php echo $data_ent["id"]; ?>"><?php echo $data_rdv["raison_sociale"]; ?> >> <?php echo $data_ent["nom"]; ?></option>
            <?php
                }
            }
            ?>
        </select></td>
                </tr>
                <tr>
                    <th>Date</th>
                    <td>
                        <input type="date" name="rdv_date" id="rdv_date" class="form-control champ_textarea"></input>
                        
                    </td>
                </tr>
                <tr>
                    <th>Heure</th>
                    <td><input type="time" name="heure" id="heure"  class="form-control" /><br /></td>
                </tr>
                <tr>
                    <th>type du rendez vous</th>
                    <td><input type="type_rdv" name="type_rdv" id="type_rdv" class="form-control"></td>
                </tr>
                <tr>
                    <th>Objet</th>
                    <td><input type="objet" name="objet" id="objet" class="form-control"></td>
                </tr>
                <tr>
                    <th>Observations</th>
                    <td><textarea name="observations" id="observations" class="form-control champ_textarea"></textarea></td>
                </tr>
                <tr>
                    <th></th>
                    <td><button type="submit" name="action" class="btn btn-success" value="1"><span class="glyphicon glyphicon-ok"></span> Ajouter</button></td>
                </tr>
            </table>
        </div>
        </form>
       
    </body>
</html>
